/*
 *  Copyright (C) 2010 Glauco
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.balisunrise.common.abstracts;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.balisunrise.common.FieldComponent;
import org.balisunrise.common.FieldLayout;

/**
 *
 * @author Glauco
 */
public abstract class AbstractPanelGroup extends AbstractFieldLayout{

    protected List<FieldLayout> layouts;
    public static final String PROP_LAYOUTS = "layouts";

    public AbstractPanelGroup() {
        layouts = new ArrayList<FieldLayout>();
    }

    /**
     * Get the value of layouts
     *
     * @return the value of layouts
     */
    public List<FieldLayout> getLayouts() {
        return layouts;
    }

    /**
     * Set the value of layouts
     *
     * @param layouts new value of layouts
     */
    public void setLayouts(List<FieldLayout> layouts) {
        List<FieldLayout> oldLayouts = this.layouts;
        this.layouts = layouts;
        changeSupport.firePropertyChange(PROP_LAYOUTS, oldLayouts, layouts);
    }

    public FieldLayout[] getFieldLayouts(){
        return layouts.toArray(new FieldLayout[layouts.size()]);
    }

    @Override
    public FieldComponent[] getFieldComponents() {
        if(layouts != null && layouts.size() > 0){
            List<FieldComponent> aux = new ArrayList<FieldComponent>();
            for (FieldLayout fl : layouts) {
                aux.addAll(Arrays.asList(fl.getFieldComponents()));
            }
            return aux.toArray(new FieldComponent[aux.size()]);
        }else{
            return super.getFieldComponents();
        }
    }


}
